package com.puyuba.puyuba.view.fragment;

import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.puyuba.puyuba.R;
import com.puyuba.puyuba.view.activity.TeacherHomePageActivity;
import com.pyb.java.basemodule.BaseFragment;
import com.pyb.java.cache.CacheUserInfo;
import com.pyb.java.cache.bean.UserInfoBean;
import com.puyuba.puyuba.network.BaseApis;

import com.puyuba.puyuba.view.activity.MainWebActivity;
import com.puyuba.puyuba.view.activity.SettingActivity;
import com.pyb.java.commonutil.ImageHelper;
import com.pyb.java.commonutil.utils.StatusBarUtil;
import com.pyb.java.commonutil.utils.StringUtil;

public class MyFragment extends BaseFragment {

    private ImageView portrait;
    private TextView username;
    private Button vipLeverBtn;
    private TextView mottoTv;
    private TextView fanTv;
    private TextView clockinTv;
    private TextView activityTv;
    private TextView praisedTv;
    private Button settingBtn;
    private Button arrowRightBtn;
    private LinearLayout llPartner;
    private LinearLayout llMechanism;
    private LinearLayout llTeacher;
    private LinearLayout llMerchant;
    private LinearLayout llMycourse;
    private LinearLayout llMylearen;
    private LinearLayout llMyquestionBank;
    private LinearLayout llAnalysisTable;
    private LinearLayout llConsultant;
    private LinearLayout llMyorder;
    private LinearLayout llContract;
    private LinearLayout llMyclient;
    private LinearLayout llEnterCustomers;
    private LinearLayout llCustomersOrder;
    private LinearLayout llChatMessage;
    private LinearLayout llInternalTraining;

    @Override
    protected void initView() {
        View viewStatusBar = (View) getActivity().findViewById(R.id.view_status_bar5);
        int screenHeight = StatusBarUtil.getStatusBarHeight(getContext());
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) viewStatusBar.getLayoutParams();
        layoutParams.height = screenHeight;
        viewStatusBar.setLayoutParams(layoutParams);
        portrait = (ImageView) getActivity().findViewById(R.id.portrait);
        username = (TextView) getActivity().findViewById(R.id.username);
        vipLeverBtn = (Button) getActivity().findViewById(R.id.vip_lever_btn);
        mottoTv = (TextView) getActivity().findViewById(R.id.motto_tv);
        fanTv = (TextView) getActivity().findViewById(R.id.fan_tv);
        clockinTv = (TextView) getActivity().findViewById(R.id.clockin_tv);
        activityTv = (TextView) getActivity().findViewById(R.id.activity_tv);
        praisedTv = (TextView) getActivity().findViewById(R.id.praised_tv);
        settingBtn = (Button) getActivity().findViewById(R.id.setting_btn);
        arrowRightBtn = (Button) getActivity().findViewById(R.id.arrow_right_btn);
        llPartner = (LinearLayout) getActivity().findViewById(R.id.ll_partner);
        llMechanism = (LinearLayout) getActivity().findViewById(R.id.ll_mechanism);
        llTeacher = (LinearLayout) getActivity().findViewById(R.id.ll_teacher);
        llMerchant = (LinearLayout) getActivity().findViewById(R.id.ll_Merchant);
        llMycourse = (LinearLayout) getActivity().findViewById(R.id.ll_mycourse);
        llMylearen = (LinearLayout) getActivity().findViewById(R.id.ll_mylearen);
        llMyquestionBank = (LinearLayout) getActivity().findViewById(R.id.ll_myquestion_bank);
        llAnalysisTable = (LinearLayout) getActivity().findViewById(R.id.ll_analysis_table);
        llConsultant = (LinearLayout) getActivity().findViewById(R.id.ll_consultant);
        llMyorder = (LinearLayout) getActivity().findViewById(R.id.ll_myorder);
        llContract = (LinearLayout) getActivity().findViewById(R.id.ll_contract);
        llMyclient = (LinearLayout) getActivity().findViewById(R.id.ll_myclient);
        llEnterCustomers = (LinearLayout) getActivity().findViewById(R.id.ll_enter_customers);
        llCustomersOrder = (LinearLayout) getActivity().findViewById(R.id.ll_customers_order);
        llChatMessage = (LinearLayout) getActivity().findViewById(R.id.ll_chat_message);
        llInternalTraining = (LinearLayout) getActivity().findViewById(R.id.ll_internal_training);

        initEvent();
        initData();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_my;
    }

    private void initData(){
        UserInfoBean.UserBean user = CacheUserInfo.getInstance().getsUserInfo().getUser();
        username.setText(user.getUname());
//        Glide.with(this)
//                .load(user.getAvatar())
//                .centerCrop()
//                .placeholder(R.mipmap.default_avatar)
//                .apply(RequestOptions.bitmapTransform(new CircleCrop()))
//                .into(portrait);
        ImageHelper.getInstance().displayWithCorner(portrait,user.getAvatar(),R.mipmap.default_avatar);
    }

    public void initEvent(){
        settingBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SettingActivity.startActivity(getContext());
            }
        });

        //测试用
        llPartner.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //base64加密
//                String url = BaseApis.APPLY_PARTEN_URL + StringUtil.getBase64(Integer.toString(CacheUserInfo.getInstance().getId()));
////                String url = "https://t.puyuba.com/app/find/taocan";
//                MainWebActivity.startMainWebActivity(getContext(),url,"申请合伙人");
                TeacherHomePageActivity.startActivity(getContext(),1);
            }
        });
        llTeacher.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MainWebActivity.startMainWebActivity(getContext(),BaseApis.authteacherUrl,"老师入驻");
            }
        });
        llMechanism.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MainWebActivity.startMainWebActivity(getContext(),BaseApis.authorganUrl,"机构入驻");
            }
        });
        llMerchant.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MainWebActivity.startMainWebActivity(getContext(),BaseApis.authstoreUrl,"商家入驻");
            }
        });

        llMycourse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MainWebActivity.startMainWebActivity(getContext(),BaseApis.mycourseUrl,"我的课程");
            }
        });
        llMyquestionBank.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MainWebActivity.startMainWebActivity(getContext(),BaseApis.myquestion,"我的题库");
            }
        });
        llMylearen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MainWebActivity.startMainWebActivity(getContext(),BaseApis.mylearnUrl,"我的学习");
            }
        });
        llMyorder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MainWebActivity.startMainWebActivity(getContext(),BaseApis.myOrderUrl,"我的订单");
            }
        });
        llCustomersOrder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MainWebActivity.startMainWebActivity(getContext(),BaseApis.userorderlistUrl,"客户订单");
            }
        });
        llInternalTraining.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MainWebActivity.startMainWebActivity(getContext(),BaseApis.trainlistUrl,"内部培训");
            }
        });
        arrowRightBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String URL= BaseApis.personDtUrl+CacheUserInfo.getInstance().getId();
                MainWebActivity.startMainWebActivity(getContext(),URL,"个人资料");
            }
        });
    }


}
